<?php

namespace App\Tools;

class FunTool
{
    public static $promptUrl = [
        [
            "https://overseas-files.dalleai.art/changsha/01.webp",
            "https://overseas-files.dalleai.art/changsha/02.webp"
        ],
        [
            "https://overseas-files.dalleai.art/changsha/03.webp",
            "https://overseas-files.dalleai.art/changsha/04.webp"
        ],
        [
            "https://overseas-files.dalleai.art/changsha/05.webp",
            "https://overseas-files.dalleai.art/changsha/06.webp"
        ],
        [
            "https://overseas-files.dalleai.art/changsha/07.webp",
            "https://overseas-files.dalleai.art/changsha/08.webp"
        ],
        [
            "https://overseas-files.dalleai.art/changsha/09.webp",
            "https://overseas-files.dalleai.art/changsha/10.webp"
        ],
    ];

    public static function getRandomUrlByPropmt($key) {
        return self::$promptUrl[$key];
    }

    public static function getAppleGoodId($apple_product_id) {
        return $apple_product_id == "dalle_annual_weekly" ? "weekly_pro" : "golden_vip";
    }

    /*
     * AF对应的appid
     * */
    public static function getAfAppidByPf($platform) {
        return $platform == 1 ? "id1580961238" : "com.jxfq.dalle";
    }

    // 获取设备id
    public static function getDeviceId() {
        return $_SERVER['HTTP_GUID'] ?? null;
    }

    // 获取版本号
    public static function getVersion() {
        return $_SERVER['HTTP_AIVERSION'] ?? '1.0.2';
    }

    // 获取安卓还是ios 1:ios 2:安卓
    public static function getPlatform() {
        return $_SERVER['HTTP_PLATFORM'] ?? 2;
    }

    /**
     * 获取hot的图标
     * @return string
     */
    public static function getHotImg() {
        return env("APP_FILES_URL")."/icon/hot.png";
    }

    /**
     * 获取hot的图标
     * @return string
     */
    public static function getVipImg() {
        return env("APP_FILES_URL")."/icon/vip.png";
    }

    /**
     * 格式化表
     * @param $tableName
     * @return string
     */
    public static function formateTable($tableName) {
        return env("DB_PREFIX") . $tableName;
    }

    /**
     * 获取当前时间
     */
    public static function getCurrentTime(){
        return date('Y-m-d H:i:s');
    }

    /**
     * 根据类型返回图片的宽高
     * @param $resolution
     * @return int[]
     */
    public static function getHeightAndWidthByResolution($resolution) {
        switch ($resolution) {
            case 2 :
                $width = 512;
                $height = 512;
                break;
            case 3:
                $width = 768;
                $height = 512;
                break;
            case 4:
                $width = 1024;
                $height = 576;
                break;
                    
            default:
                $width = 512;
                $height = 768;
                break;
        }

        return [$width,$height];
    }

    /**
     * 根据类型返回图片的宽高
     * @param $resolution
     * @return int[]
     */
    public static function getImg2ImgHeightAndWidthByResolution($resolution) {
        switch ($resolution) {
            case 2 :
                $width = 768;
                $height = 768;
                break;
            case 3:
                $width = 1024;
                $height = 768;
                break;
            default:
                $width = 768;
                $height = 1024;
                break;
        }

        return [$width,$height];
    }

    /**
     * 获取高清图所使用的点数
     * @return bool|mixed|string
     */
    public static function getHighDrawingDot() {
        return env("HIGH_DRAWING_DOT");
    }

    /**
     * 获取用户免费试用的次数
     * @return int
     */
    public static function getFreeNum() {
        return 2;
    }
    /**
     * 获取当前时间减去hour小时的时间
     */
    public static function getReduceTime($hour = 0){

        return date('Y-m-d H:i:s');
        // return date('Y-m-d H:i:s', strtotime("-$hour hour"));

    }

    /**
     * 分享图片的后缀
     * @return string
     */
    public static function getShareImgMark() {
        $mark = '!down';
        $platform = array_key_exists("HTTP_PLATFORM",$_SERVER) ? $_SERVER['HTTP_PLATFORM'] : 2;
        if ($platform == 1) {
            $mark = "!apple_down";
        } else {
            if (isset($_SERVER['HTTP_AI_LAN']) && $_SERVER['HTTP_AI_LAN'] == "zh") {
                $mark = "!android_zh_down";
            } else {
                $mark = "!android_en_down";
            }
        }
        return $mark;
    }

    /**
     * 二维数组随机排序
     * @param $lists
     * @return array|mixed
     */
    public static function shuffleLists($lists){
        if(!is_array($lists)){
            return $lists;
        }else{
            $keys = array_keys($lists);
            //打乱数组的键排序
            shuffle($keys);
            $result = array();
            foreach ($keys as $k=> $key){
                $result[$k] = $lists[$key];
            }
        }
        return $result;
    }

    /**
     * 获取高清图所使用的点数
     * @return bool|mixed|string
     */
    public static function getImageVideoDot() {
        return 50;
    }

}